import {
	BaseUrl
} from '@/config/const.js'
import {
	get_token
} from '@/auth/token'
// 文件上传
export async function commonUploadPic(data) {
	return new Promise(function(resolve, reject) {
		uni.uploadFile({
			url: BaseUrl + '/common/upload/pic', //上传图片api
			filePath: data.path || data,
			name: 'pic', // 后端接收的字段
			header: {
				"Content-Type": "multipart/form-data",
				'X-Access-Token': get_token()
			},
			success: (res) => {
				console.log(res, 'success')
				resolve(res)
			},
			fail: (res) => {
				console.log(res, 'fail')
				reject(res)
			}
		});
	});
}
export function uploadFile(tempFilePath) {
	return new Promise(function(resolve, reject) {
		uni.uploadFile({
			url: BaseUrl + '/common/upload/pic', //仅为示例，非真实的接口地址
			header: {
				"Content-Type": "multipart/form-data",
				'X-Access-Token': get_token()
			},
			filePath: tempFilePath,
			name: 'pic',
			success: (res) => {
				// console.log(res, 'uploadFileSuccess')
				resolve(JSON.parse(res.data).result);
			},
			fail: (res) => {
				// console.log(res, 'uploadFileFail')
				reject(res)
			}
		});
	});
}